﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using StructureMap.Configuration.DSL;

namespace MethodWorx.CMS.UI.Application.Dependencies
{
    public class ModelFactoryRegistry : Registry
    {
        /// <summary>
        /// Register all models in the application with a generic structure map
        /// model factory
        /// </summary>
        public ModelFactoryRegistry()
        {
            foreach (var type in this.GetType().Assembly.GetTypes())
            {
                if (type.Namespace != null && type.Namespace.EndsWith(".Models"))
                {
                    this.For(typeof(IModelFactory<>).MakeGenericType(new Type[] { type }))
                        .Use(typeof(ModelFactory<>).MakeGenericType(new Type[] { type }));
                }
            }
        }
    }
}